// new pizza builder javascript


function reDirPizzaSize(id){
  window.location = "index.php?act=pizza-builder&id=" + id;	
}
$(function() {
  
  var lang = window.rbiller.lang.pizzabuilder;

  $( "#pizza-tabs" ).tabs();

  function calculatePizzaBuilder(){
    $.ajax({
      type: "POST",
      url:  'ajax.php?function=calculate-pizza-builder&t='  + new Date().getTime(),
      data:  $('#pizzaform').serialize(),
      success: function(msg){
        if(msg.substr(0,5) === 'error'){
          $(".topping").attr('disabled',true);
          alert(msg.substr(6,msg.length - 1));
        } else {				  
          $(".topping").attr('disabled',false); 
          $('#pizza_price').html(msg);
        }
      }
    });	

  }
		
  $('.calc').bind('click', calculatePizzaBuilder);
  
  $('.add-pizza').bind('click', function() {
    $.ajax({
      type: "POST",
      url:  'ajax.php?function=calculate-pizza-builder&add=1&t='  + new Date().getTime(),
      data:  $('#pizzaform').serialize(),
      success: function(msg){
        $('#pizza_price').html(msg);
      }
    });	
                  
    $('.popup').html("<p>" + lang.pizza_added + "</p>");

    var buttons = {};
    buttons[lang.checkout_button] = function() {
      $( this ).dialog( "close" );
      window.location = "index.php?act=checkout"
    };

    buttons[lang.continue_button] = function() {
      //$( this ).dialog( "close" );
      location.reload(true);
    
    };

    $( '.popup' ).dialog({
            width: 400,
            height: 200,
            buttons: buttons 
    });		
    return false;
  });
  
      
  calculatePizzaBuilder();
});
	
